package org.huamoxi.controller;

import org.apache.poi.ss.formula.functions.T;
import org.huamoxi.param.LoginParam;
import org.huamoxi.result.Result;
import org.huamoxi.service.LoginService;
import org.huamoxi.utils.ResultUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@RestController
@RequestMapping("/user")
public class AuthController {
    @Resource
    LoginService loginService;

    @PostMapping("/login")
    public Result<T> login(@RequestBody LoginParam loginUser, HttpServletRequest request, HttpServletResponse response) {
        return loginService.login(loginUser, request, response);
    }

    @RequestMapping("/refreshToken")
    public Result<T> refresh(@RequestHeader("Authorization") String token) {
        return ResultUtils.success(loginService.refreshToken(token));
    }
}
